<?php
function ListCustomTourMap()
{
    global $dbsql,$language;
    
    $sql_where  = "from tblcustomtourmap ";
    
    $sql_select = "select count(iId) as count ".$sql_where;
    $result     = $dbsql->query_fetch($sql_select);
    $count_all  = $result['count'];
	list($lf,$la)=Slit_Page($count_all);
    
    $sql_select = "select * ".$sql_where." order by iId desc limit $lf,$la";
    return $dbsql->load($sql_select);
    
}

function init()
{
    global $dbsql,$language;
    
    if($_GET['act']=='reset')
    {
        $dbsql->query('drop table tblcustomtourmap',true);
        $dbsql->query('drop table tblcustomfield',true);
    }
    $table = "CREATE TABLE `tblcustomtourmap` (
              `iId` int(11) NOT NULL AUTO_INCREMENT,
              `cName` varchar(200) DEFAULT NULL,
              `cEmail` varchar(200) DEFAULT NULL,
              `cPhone` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
              `cCountry` varchar(50) CHARACTER SET latin1 DEFAULT NULL,
              `dTravellingDate` date DEFAULT NULL,
              `iNumOfPeople` int(11) DEFAULT NULL,
              `cComments` varchar(200) CHARACTER SET latin1 DEFAULT NULL,
              `cLocations` varchar(500) DEFAULT NULL,
              `cActivities` varchar(200) DEFAULT NULL,
              `cAccommodation` varchar(200) DEFAULT NULL,
              `iStatus` int(1) DEFAULT NULL,
              `iPostDate` int(11) DEFAULT NULL,
              PRIMARY KEY (`iId`)
            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
            
            
     $table_customfield = "CREATE TABLE `tblcustomfield` (
              `iId` int(11) NOT NULL AUTO_INCREMENT,
              `cName` varchar(200) DEFAULT NULL,
              `iType` int(5) DEFAULT NULL,
              `iOrder` int(11) DEFAULT NULL,
              `cLanguage` char(3) CHARACTER SET latin1 DEFAULT NULL,
              PRIMARY KEY (`iId`)
            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
            
                   
    $tablehas = $dbsql->query("show tables like 'tblcustomtourmap';");
    if($dbsql->num_rows($tablehas)==0)
    {
        $dbsql->query($table,true);
    }
    
    $tablehas = $dbsql->query("show tables like 'tblcustomfield';");
    if($dbsql->num_rows($tablehas)==0)
    {
        $dbsql->query($table_customfield,true);
    }
    
}

function option_customfield($select)
{
    $options = array();
    $options[] = 'Activities grade ';
    $options[] = 'Accommodation Style ';
    
    $html = '';
    foreach($options as $i => $option)
    {
        if($select == $i)
        {
            $html .= '<option value="'.$i.'" selected>'.$option.'</option>';
        }else
        {
            $html .= '<option value="'.$i.'">'.$option.'</option>';
        }
    }
    return $html;
}

function listCustomField($catid = 0)
{
    global $dbsql,$language;
    
    $sql_select = "select * from tblcustomfield where iType = $catid order by iOrder";
    return $dbsql->load($sql_select);
}
?>